package com.cxyjy.travelguide.service.Impl;

import com.cxyjy.common.BusinessException;
import com.cxyjy.travelguide.dal.dataobject.ExternalBaiduAiImageDO;
import com.cxyjy.travelguide.entity.ExternalBaiduAiImage;
import com.cxyjy.travelguide.mapper.ExternalBaiduAiImageMapper;
import com.cxyjy.travelguide.service.BaiduAiImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

import static com.cxyjy.common.util.JObjectUtil.isEmpty;

/**
 * @Author: jony
 * @Date : 2025/5/22 09:43
 * @VERSION v1.0
 */
@Service("BaiduAiImageService")
public class BaiduAiImageServiceImpl implements BaiduAiImageService {
    @Autowired
    ExternalBaiduAiImageMapper baiduAiImageMapper;
    @Override
    public List<String> getContSignListByObjectCode(String objectCode) {
        Map<String,List<String>> resultMap = new HashMap<>();
        List<ExternalBaiduAiImage> externalBaiduAiImages = baiduAiImageMapper.selectByCode(objectCode);
        if(externalBaiduAiImages.isEmpty()){
            throw new BusinessException("该code下没有在图库中查询出对应的图片！");
        }
        List<String> contSignList = new ArrayList<>();
        for(ExternalBaiduAiImage e : externalBaiduAiImages){
            contSignList.add(e.getContSign());
        }
        return contSignList;
    }

    @Override
    public Map<String, Object> getClassIdByObjectCode(String objectCode) {
        Map<String, Object> codeMap = new HashMap<>();
        ExternalBaiduAiImageDO baiduAiImageDO = baiduAiImageMapper.selectFirstOne(ExternalBaiduAiImageDO::getCode, objectCode);
        if(isEmpty(baiduAiImageDO)){
            throw new BusinessException("文物code: "+ objectCode + " 未查询出对应的城市id或景区id");
        }
        codeMap.put("classId1",baiduAiImageDO.getClassId1());
        codeMap.put("classId2",baiduAiImageDO.getClassId2());
        return codeMap;
    }

    @Override
    public List<ExternalBaiduAiImageDO> getBaiduAiImageByObjectCode(String objectCode) {
        return baiduAiImageMapper.selectList(ExternalBaiduAiImageDO::getCode,objectCode);
    }
}
